import React, { Component } from 'react';
import { fromJS}  from 'immutable'
// import Pushwarehouse from "./../Warehouse/Pushwarehouse/index.tsx"


// import 
import { Table, Button } from 'antd';
import Model from './ui/Model';
import Assigned from './ui/Assigned';
import  store  from "../../../store/index"

// import connect from './connect'

import { outStorage} from "../../../model/storageModel"
// import { putStorage} from "@/model/storageModel"
// import Model from "@ views/Warehouse/Pushwarehouse/ui/Model."

const columns = [
  {
    title: '出库日期',
    dataIndex: 'outStorageDate',
  },
  {
    title: '出库单编号',
    dataIndex: 'outStorageNum',
  },
  {
    title: '采购单编号',
    dataIndex: 'agec',
  },
  {
    title: '出库状态',
    dataIndex: 'outStorageState',
  },
  {
    title: '出库类型',
    dataIndex: 'outStorageType',
  },
  {
    title: '出库确认',
    dataIndex: 'outStorageState',
  },
  {
    title: '入货仓库',
    dataIndex: 'closedStore',
  },
  {
    title: '配送员',
    dataIndex: 'outStorageOr',
  },
  {
    title: '仓管员',
    dataIndex: 'outStorageManagement',
  },
  {
    title: '操作',
    dataIndex: 'fuck',
  },
];

let data2: any = [];
// for (let i = 0; i < 46; i++) {
//   data.push({
//     key: i,
//     name: `2017.12.03 ${i}`,
//     age: " RK160727154701",
//     agec: " GG160727154701",
//     address: `待入库 ${i}`,
//     storeState: `待入库 ${i}`,
//     storeType: `一般入库 ${i}`,
//     supply: ` 89${i}24`,
//     closedStore: ` 长江仓库`,
//     storer: `李四`,
//     closed: `张三`,
//     fuck: <Model></Model>,
//   });
// }

// @connect
class index extends Component {
   
  // constructor(props:any){
  //     super(props)
  //     this.state =store.getState()
  //     store.subscribe(()=>{
  //       this.setState(state =>store.getState())
  //   })

  // };
  constructor(props:any){
    super(props)
    store.subscribe(()=>{
      // console.log(store.getState().getIn(['sr']).toJS());
      //  已经入库
      // this.setState(state =>store.getState().getIn(['sr']).toJS())
      this.state.datasss =store.getState().getIn(['sr']).toJS().pushStore
       })
     

  };

  state = {
    selectedRowKeys: [], // Check here to configure the default column
    loading: false,
    datasss:[]

  };

  start = () => {
    this.setState({ loading: true });
    // ajax request after empty completing
    setTimeout(() => {
      this.setState({
        selectedRowKeys: [],
        loading: false,
      });
    }, 1000);
     
    // this.setState({  datasss:   this.state.datasss.map((item:any) => {
    //   if(item.putStorageState=="入库待确认"){
    //     return Object.assign(item,{ fuck: <Model key={item.key}></Model>});
    //   }else{
    //     return  item
    //   }}) });



  };

  async componentDidMount (){

    // store.subscribe(()=>{
    //   console.log(store.getState());
    //    })

    let res = await  outStorage()
    // let  Pushdata =res.data.data;
     data2=res.data.data.map((item:any) => {
      if(item.outStorageState=="出库待确认"){
        return Object.assign(item,{ fuck: <Model key={item.key}></Model>});
      }else{
        return  item
      }});

    this.setState({
      datasss:data2
    })
    // 直接发送 一个 action  的返回值
    // store.dispatch({
    //   type:"pushredux",
    //   data:this.state.datasss
    // })


    // this.state =store.getState()
      
  
  }

  //  store.getState


  // 多选处理函数
  onSelectChange = (selectedRowKeys: any) => {
    // 选中了哪一项
    console.log('selectedRowKeys changed: ', selectedRowKeys);

    // store.dispatch({
    //   type:"pushselect",
    //   data:selectedRowKeys
    // })
    this.setState({ selectedRowKeys });
  };

  render() {
    // console.log(store);
    
    
    return (

      // 重新加载+++++++++++++++++++++++++++++++++++
      <div style={{ width: "100%" }}>
      
        <Table  columns={columns} dataSource={  this.state.datasss} bordered />
        <Assigned/>
      </div>
    );
  }

}

export default index;
